@extends('admin.layout.base')
@section('title', '系统消息列表')
@section('content')
<div class="content-wrapper">
    <!-- Content Header (Page header) -->
    <section class="content-header">
        <h1>
            系统消息列表页面
        </h1>
        <ol class="breadcrumb">
            <li><a href="{{ url('/admin') }}"><i class="fa fa-dashboard"></i> 首页</a></li>
            <li class="active">系统消息管理</li>
        </ol>
    </section>
    <!-- Main content -->
    <section class="content">
        <div class="row">
            <div class="col-xs-12">
                <div class="box">
                    <div class="box-header">
                        <a class="btn btn-success" href="{{ url('/admin/message/create') }}">
                            <i class="fa fa-plus"></i> 发消息
                        </a>
                        <div class="box-tools col-xs-6">
                            <form action="{{ url('/admin/message') }}" method="get" class="form-inline">
                                <div class="form-group">
                                    <label for="msg_title">标题：</label>
                                    <input type="text" name="title" id="msg_title" value="{{ old('msg_title') }}" class="form-control"/>
                                </div>
                                <div class="form-group">
                                    <label for="msg_type">消息类型：</label>
                                    <select name="type" id="msg_type" class="form-control">
                                        <option value="9" selected>全部</option>
                                        <option value="0">系统消息</option>
                                        <option value="1">会员消息</option>
                                        <option value="2">管理员消息</option>
                                    </select>
                                </div>
                                <button type="submit" class="btn btn-default"><i class="fa fa-search"></i></button>
                            </form>
                        </div>
                    </div>
                    <!-- /.box-header -->
                    <div class="box-body table-responsive no-padding">
                        <table class="table table-hover table-bordered">
                            <tr>
                                <th>#</th>
                                <th>消息标题</th>
                                <th>消息类型</th>
                                <th>发送时间</th>
                                <th>操作</th>
                            </tr>
                            @foreach($messages as $msg)
                            <tr>
                                <td>{{ $msg->id }}</td>
                                <td>{{ $msg->msg_title }}</td>
                                <td>
                                    @if($msg->msg_type == 1)
                                        会员消息
                                    @elseif($msg->msg_type == 2)
                                        管理员消息
                                    @else
                                        系统消息
                                    @endif
                                </td>
                                <td>{{ $msg->msg_time }}</td>
                                <td>
                                    <a href="{{ url("/admin/message/{$msg->id}") }}" class="btn btn-info">查看</a>
                                    <a href="{{ url("/admin/message/{$msg->id}") }}" class="btn btn-danger del">删除</a>
                                </td>
                            </tr>
                            @endforeach
                        </table>
                    </div>
                    <!-- /.box-body -->
                    <div class="box-footer">
                        {!! $messages->appends(['title'=>old('title'), 'type'=>old('type')])->render() !!}
                    </div>
                </div>
                <!-- /.box -->
            </div>
        </div>
    </section>
    <!-- /.content -->
</div>
@endsection
@section('pluginscript')
<!-- Slimscroll -->
<script src="{{ asset('/dist/admin/plugins/slimScroll/jquery.slimscroll.min.js') }}"></script>
<!-- FastClick -->
<script src="{{ asset('/dist/admin/plugins/fastclick/fastclick.js') }}"></script>
<script type="text/javascript">
    $(function(){
        $.ajaxSetup({
            headers: {
                'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
            }
        });
        
        // 删除
        $('.del').click(function(){
            var url = $(this).attr('href');
            var tr = $(this).parents('tr');
            var result = confirm('确定要删除？');
            
            if(result){
                $.ajax({
                    url: url,
                    type:'DELETE',
                    success:function(msg){
                        if(msg.status == '1'){
                            tr.remove();
                        } else {
                            alert(msg.info);
                        }
                    }
                });
            }
            return false;
        });
    });
</script>
@endsection
